package com.io.service.impl;

import com.io.dao.UserDaoI;
import com.io.dto.UserReqDTO;
import com.io.dto.UserResDTO;
import com.io.entity.User;
import com.io.service.UserServiceI;
import com.lambdaworks.crypto.SCryptUtil;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * The class/interface
 *
 * @author guodd
 * @version 1.0 use jdk 1.8
 */
@Service
public class UserServiceImpl implements UserServiceI {
    @Autowired
    private UserDaoI userDaoI;

    @Override
    public UserResDTO register(UserReqDTO userReqDTO) {
        User user = new User();
        BeanUtils.copyProperties(userReqDTO, user);
        user.setPassword(SCryptUtil.scrypt(userReqDTO.getPassword(), 32768, 8, 1));
        User save = userDaoI.save(user);
        return save.buildInfo(user);
    }
}
